import Context from './context.js';
import _ from 'lodash';
import predictUtils from '../../utils/predict.js';




Context(async({ config, getMarkPrice, openLong, getTrade, funcGetSymbolDailPrice, utils }) => {
    await utils.predict('BRUSDT', '3m', 120, '2025-08-27 13:45', async (result) => {
        console.log('预测结果:', result);
    });

    return;
    const symbol = 'AIOTUSDT';
    const trades = getTrades();
    const times = {
        win: 0,
        loss: 0,
    }
    for (const h of trades.history) {
        if (times.win >= 1) {
            continue;
        }
        if (h.rp > 0) {
            times.win++;
        }
        if (h.rp < 0) {
            times.loss++;
            times.win = 0;
        }
    }
    times.loss = 3;
    times.loss = Math.min(times.loss, 3);

    let rate = 1 * Math.pow(2, times.loss);
    console.log(rate);
    return;
    console.log(times);



    // const symbolTrades = _.get(trades, `symbols.${symbol}`, []);
    // // 12小时内的亏损次数
    // const lossTimes = symbolTrades.filter(t => t.rp < 0 &&
    //         t.timestamp > new Date().getTime() - 1000 * 60 * 60 * 12).length;

    // console.log(lossTimes);
    // // 如果亏损次数大于等于2次，则不建仓
    // if (lossTimes >= 2) {
    //     console.log([ 'lossTimes', lossTimes, symbol ]);
    //     return false;
    // }

    return;
    const pirce = await getMarkPrice(symbol);
    const quantity = config.balance / pirce;
    console.log(pirce, quantity);
    openLong(symbol, quantity, config.takeProfitPct, config.stopLossPct);
    // duichong(symbol, quantity, config.takeProfitPct, config.stopLossPct);
    setInterval(() => {
        console.log(getTrades());
    }, 1000);
});
